<?php
class ContentController extends Controller{
	private $db;
	public function __init(){
		$this->db= K('Content'); //new 实例化
	}
	//显示文章列表
	public function index(){
		$data = $this->db->getList();
		$this->assign($data);
		$this->display();
	}
	//发布文章
	public function add(){
		if(IS_POST){
			if($this->db->addContent()){
				$this->success('发布成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$category= K('Category')->getList();
			$this->assign('category',$category);
			$this->display();
		}
	}
	//修改文章
	public function edit(){
		if(IS_POST){
			if($this->db->editContent()){
				$this->success('修改成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$category= K('Category')->getList();
			$this->assign('category',$category);
			//读取文章数据
			$field = $this->db->field("*,content.keywords,content.description")->find(Q('aid',0,'intval'));
			// 缩略图处理(为了编辑时正常显示)
			$field['thumb']=array(
				array('path'=>$field['thumb'])
			);
			$this->assign('field',$field);
			$this->display();
		}
	}
	//删除文章
	public function del(){
		$aid=Q('aid',0,'intval');
		if($this->db->delContent($aid)){
			$this->success('删除成功','index');
		}else{
			$this->error($this->db->error);
		}
	}

}
?>